<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工登录</title>
    <link rel="stylesheet" href="/css/elementUI.css">
    <script src="/js/vue.js"></script>
    <script src="/js/elementUI.js"></script>
    <script src="/js/axios.js"></script>
</head>
<body>

<div id="app">


    账号： <el-input v-model="user.username" style="width: 200px" placeholder="请输入用户名" clearable></el-input>
    <br>
    密码：
    <el-input v-model="user.password" style="width: 200px" placeholder="请输入密码" clearable show-password></el-input>
    <br>
    <el-button type="primary" @click="toLogin">登录</el-button>

</div>
<script>

    new Vue({
        el:"#app",
        data:{
            user:{
                username:"",
                password:""
            }
        },
        watch:{
        },
        methods:{
            toLogin(){
                axios.post("/user/login",this.user).then(res=>{
                    if(res.data.token){
                        this.$message.success("登录成功")
                        //
                        let user = res.data.user;
                        let token = res.data.token;

                        localStorage.setItem("userInfo",JSON.stringify(res.data));

                        if(user.dname=="采购部"){
                            location.href = "/program.html"
                        }else if(user.dname=="管理部"){
                            location.href = "/programAdmin.html"
                        }
                    }else{
                        this.$message.error(res.data)
                    }
                })
            },
            initData(){

            }

        },
        created(){
            this.initData()
        }
    })
</script>

</body>
</html>